/**
 * de.herberlin.sudoku.gui.HelpWindow
 */
package de.herberlin.sudoku.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.IOException;
import java.net.URL;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import de.herberlin.sudoku.Main;

/**
 * @author herberlin
 * @created 18.07.2006
 */
public class HelpWindow extends JFrame {

	public HelpWindow(String title, URL url) throws IOException {

		super(title);

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
		final JEditorPane edit = new JEditorPane(url);
		edit.setPreferredSize(new Dimension(320, 240));
		edit.setEditable(false);
		edit.setEnabled(true);
		edit.addHyperlinkListener(new HyperlinkListener() {

			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
					final URL url = e.getURL();
					if (url != null) {
						new Thread() {
							public void run() {
								try {
									edit.setPage(url);
								} catch (IOException e1) {
									Main.showError(null, e1);
								}
							}
						}.start();
					}
				}
			}
		});
		getContentPane().add(new JScrollPane(edit), BorderLayout.CENTER);
		pack();
		setVisible(true);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			new HelpWindow("Test", HelpWindow.class
					.getResource("/help/about.html"));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
